home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / vlapak1.zip / VLAJEDI.ZIP / JEDI.ASM < prev    next >
Assembly Source File  |  1993-08-08  |  10KB  |  350 lines

  1.     ────────────────────────────────────────────────────────────────────
  2.     ;   Return of the jedi- type credits. Written by Draeden of VLA
  3.     ;        Started on 08.10.1993      Finished on 08.10.1993
  4.     ;
  5.     ;        Copyright 1993 by VLA  ■  Use by permission only!
  6.     ────────────────────────────────────────────────────────────────────
  7.     IDEAL
  8.     DOSSEG
  9.     MODEL SMALL
  10.     STACK 400h
  11.  
  12.     CODESEG
  13.     P386N
  14.     ASSUME CS:@CODE, DS:@CODE
  15.     LOCALS
  16. ────────────────────────────────────────────────────────────────────────────
  17. STRUC VGALINE
  18.     Dest        dw      0   ;offset of left of line on screen
  19.     Source      dw      0   ;offset to source for this line
  20.     Indent      dw      0   ;amt indented from edge to start of line
  21.     Old_Indent  dw      0   ;last indent so we know to erase
  22.     Real_Width  dw      0   ;between 0 and 320 if Virt_Width < 320 then 
  23.                             ; Real = Virt
  24.     Virt_Width  dw      0   ;Virtual width of line, is the index into 
  25.                             ; step chart pointers - only even values are
  26. ENDS                        ; are permitted (and with 0FFFEh)
  27. ────────────────────────────────────────────────────────────────────────────
  28. Step_Chart  dw  183 dup (?) ;the max width for a line is 366 bytes
  29.                             ;(virtual) cause that's all that would fit
  30.                             ; in 64k
  31.  
  32. LABEL TheLines VGALINE     
  33.     i=0
  34.     REPT 200 
  35.         VGALINE <i*320,?,160,160,0>
  36.         i=i + 1
  37.     ENDM                    ;have all 200 so we have the possibility of
  38.                             ; full screen action
  39. Step_Seg    dw  0           ;segment of step chart
  40. VGASeg      dw  0A000h  
  41. Image_Seg   dw  0           ;source for GFX
  42. ────────────────────────────────────────────────────────────────────────────
  43.     ────────────────────────────────────────────────────────────────────
  44.     ;Takes the info for each line and displays the whole screen cleaning
  45.     ;up after the last one as it goes.  This routine REALLY pushes the 
  46.     ;limits...  May be damaging to your health. Way complex. =)
  47.     ────────────────────────────────────────────────────────────────────
  48. PROC Display_Lines NEAR
  49.     pusha
  50.     push    ds es fs gs                     ;save everything
  51.     mov     ax,cs
  52.     mov     ds,ax                           ;setup all the segments
  53.     mov     es,[VGAseg]
  54.     mov     fs,[Step_Seg]
  55.     mov     gs,[Image_Seg]
  56.  
  57.     xor     bx,bx                           ;start on line 0
  58. @@DrawLineLoop:
  59.     mov     cx,[bx + TheLines.Indent]
  60.     sub     cx,[bx + TheLines.Old_Indent]   ;if old>=new then we dont erase
  61.     jle     @@NoErase                       ; otherwise, CX = # bytes to del
  62.  
  63.     mov     di,[bx + TheLines.Dest]         ;erase the front
  64.     add     di,[bx + TheLines.Old_Indent]
  65.     xor     al,al
  66.     push    cx
  67.     rep     stosb
  68.     pop     cx
  69.     add     di,[bx + TheLines.Real_Width]   ;and erase the end
  70.     rep     stosb
  71.  
  72. @@NoErase:
  73.     cmp     [bx + TheLines.Virt_Width],0    ;dont draw width 0
  74.     je      @@DoneLine
  75.  
  76.     mov     di,[bx + TheLines.Dest]
  77.     add     di,[bx + TheLines.Indent]       ;point to the beginning of Dest
  78.  
  79.     mov     bp,[bx + TheLines.Source]       ;grab the base for source
  80.     push    bx
  81.     mov     cx,[bx + TheLines.Real_Width]   ;grab real width in CX
  82.     mov     bx,[bx + TheLines.Virt_Width]   ;grab virtual width of line
  83.     and     bx,0fffeh
  84.     mov     bx,[bx + Step_Chart]            ;get the offset to the step stuff
  85.     
  86. @@Little_Loop:
  87.     mov     si,[fs:bx]                      ;grab source offset
  88.     add     bx,2                            ;point to next offset 
  89.  
  90.     mov     al,[gs:bp + si]                 ;grab the byte
  91.     stosb                                   ;store it - if you run a 486
  92.                                             ; mov [es:di],al  inc di 
  93.                                             ;MAY be faster
  94.     loop    @@Little_Loop
  95.  
  96.     pop     bx                              ;done, restore BX
  97.  
  98. @@DoneLine:
  99.     mov     ax,[bx + TheLines.Indent]       ;copy over indent and that's that
  100.     mov     [bx + TheLines.Old_Indent],ax
  101.     
  102.     add     bx,(size VGALine)
  103.     cmp     bx,(size VGALine)*200
  104.     jb      @@DrawLineLoop
  105.  
  106.     pop     gs fs es ds
  107.     popa
  108.     ret
  109. ENDP
  110.     ────────────────────────────────────────────────────────────────────
  111.     ; This sets up the step charts for each width from 0 to 366, only
  112.     ;doing even values. Also fills in the step offset chart.
  113.     ────────────────────────────────────────────────────────────────────
  114. Pic_Width   =   320
  115.  
  116. PROC Setup_Step NEAR
  117.     pushad
  118.     push    ds es
  119.     mov     ax,cs
  120.     mov     ds,ax
  121.     mov     es,[Step_Seg]
  122.  
  123.     xor     ebp,ebp           ;current width
  124.     xor     si,si           ;Step offset index
  125.     xor     di,di           ;offset in Step_Seg
  126. @@StepLoop:
  127.     mov     [si + Step_Chart],di    ;save offset for current one
  128.     or      bp,bp
  129.     je      @@Null
  130.     
  131.     mov     eax,320 * 10000h
  132.     xor     edx,edx
  133.     div     ebp
  134.     
  135.     mov     edx,eax
  136.     ror     edx,16  ;dx= int step, high EDX = fractional step
  137.  
  138.     mov     cx,bp                   ;get the width
  139.     xor     eax,eax                 ;int low, frac hi current offset
  140.     cmp     cx,320
  141.     jbe     @@StoreLoop
  142.  
  143.     sub     cx,320
  144.     movzx   ecx,cx
  145.     mov     eax,edx
  146.     ror     eax,16
  147.     push    edx
  148.     mul     ecx
  149.     shr     eax,1
  150.     ror     eax,16
  151.     pop     edx
  152.     mov     cx,318
  153. @@StoreLoop:
  154.     stosw                           ;store current offset
  155.     add     eax,edx                 ;increase the offset
  156.     adc     eax,0                   ;let fractions carry over..
  157.     loop    @@StoreLoop
  158.  
  159. @@Null:
  160.     add     si,2
  161.     add     bp,2
  162.     cmp     bp,366                  ;max that can fit in 64k
  163.     jb      @@StepLoop
  164.  
  165.     pop     es ds
  166.     popad
  167.     ret
  168. ENDP
  169.     ────────────────────────────────────────────────────────────────────
  170.     ;Sets up the widths and indent of all TheLines so that it makes
  171.     ; it look like text going back into the distance..
  172.     ────────────────────────────────────────────────────────────────────
  173. PROC Setup_Screen NEAR
  174.     pusha
  175.     push    ds
  176.     mov     ax,cs
  177.     mov     ds,ax
  178.     
  179.     mov     si,(size VGALine) * 80
  180.     mov     cx,100
  181.     mov     bx,130                  ;width
  182.     mov     ax,160-130/2            ;indent
  183.     xor     dx,dx                   ;source
  184. @@FillLoop:
  185.     mov     [si + TheLines.Virt_Width],bx
  186.     mov     [si + TheLines.Real_Width],bx
  187.     cmp     bx,320
  188.     jbe     @@WOK
  189.     mov     [si + TheLines.Real_Width],320
  190. @@WOK:
  191.     mov     [si + TheLines.Indent],ax
  192.     mov     [si + TheLines.Old_Indent],ax
  193.     or      ax,ax
  194.     jns     @@Iok
  195.     mov     [si + TheLines.Indent],0
  196.     mov     [si + TheLines.Old_Indent],0
  197. @@Iok:
  198.     mov     [si + TheLines.Source],dx
  199.  
  200.     add     dx,320
  201.     add     bx,2
  202.     dec     ax
  203.     add     si,(size VGAline)
  204.     cmp     si,(size VGAline)*200
  205.     jae     @@BYE
  206.     loop    @@FillLoop
  207.  
  208. @@BYE:
  209.  
  210.     pop     ds
  211.     popa
  212.     ret
  213. ENDP
  214.     ────────────────────────────────────────────────────────────────────
  215.     ; Scrolls the data up by one line, adjusting all the source pointers
  216.     ;in TheLines.  Also writes one additional line somewhere.
  217.     ────────────────────────────────────────────────────────────────────
  218. PROC Scroll_Text
  219.     pusha
  220.     push    ds
  221.     mov     ax,cs
  222.     mov     ds,ax
  223.  
  224.     mov     si,0
  225.     mov     cx,200
  226. @@IncLoop:
  227.     mov     ax,[si + TheLines.Source]
  228.     add     ax,320
  229.     cmp     ax,64000
  230.     jb      @@NotOver
  231.     xor     ax,ax
  232. @@NotOver:
  233.     mov     [si + TheLines.Source],ax
  234.     add     si,(size VGALine)
  235.     loop    @@IncLoop
  236.  
  237.     pop     ds
  238.     popa
  239.     ret
  240. ENDP
  241.     ────────────────────────────────────────────────────────────────────
  242.     ;Loads in a TGA picture to display
  243.     ────────────────────────────────────────────────────────────────────
  244. STRUC Pal
  245.     R   db  ?
  246.     G   db  ?
  247.     B   db  ?
  248. ENDS
  249.  
  250. FileName_TGA    db  "Test2.TGA",0
  251. Palette         Pal 256 dup (<>)
  252.     
  253. PROC Load_TGA NEAR
  254.     pusha
  255.     push    ds
  256.     mov     ax,cs
  257.     mov     ds,ax
  258.  
  259.     mov     dx,offset FileName_TGA
  260.     mov     ax,3d00h
  261.     int     21h
  262.     jc      @@BYE
  263.     mov     bx,ax
  264.  
  265.     mov     ax,4200h                    ;move FP rel to start
  266.     xor     cx,cx                       ; get past header
  267.     mov     dx,18
  268.     int     21h
  269.  
  270.     mov     dx,offset Palette           ;read in palette
  271.     mov     cx,768
  272.     mov     ah,3fh
  273.     int     21h
  274.  
  275.     mov     si,offset Palette           ;fix palette
  276.     mov     cx,256
  277. @@FPL:
  278.     mov     al,[(Pal PTR si).R]         ;switch R&B and make 6bit
  279.     mov     ah,[(Pal PTR si).G]
  280.     mov     dl,[(Pal PTR si).B]
  281.     shr     al,2
  282.     shr     ah,2
  283.     shr     dl,2
  284.     mov     [(Pal PTR si).R],dl
  285.     mov     [(Pal PTR si).G],ah
  286.     mov     [(Pal PTR si).B],al
  287.     add     si,(size Pal)
  288.     loop    @@FPL
  289.  
  290.     mov     si,offset Palette           ;write palette
  291.     mov     dx,3c8h
  292.     xor     al,al
  293.     out     dx,al
  294.     inc     dx
  295.     mov     cx,256*3
  296.     rep outsb
  297.  
  298.     mov     ds,[Image_Seg]              ;read in picture
  299.     xor     dx,dx
  300.     mov     cx,64000
  301.     mov     ah,3fh
  302.     int     21h
  303.  
  304.     mov     ah,3eh                      ;close it up
  305.     int     21h
  306.  
  307. @@BYE:
  308.     pop     ds
  309.     popa
  310.     ret
  311. ENDP
  312. ────────────────────────────────────────────────────────────────────────────
  313. START:
  314.     mov     ax,cs
  315.     mov     es,ax
  316.     mov     ds,ax
  317.  
  318.     mov     ax,ss
  319.     mov     bx,sp
  320.     shr     bx,4
  321.     inc     bx
  322.     add     ax,bx               ;find 1st available seg after Stack
  323.  
  324.     mov     [Step_Seg],ax
  325.     add     ax,1000h
  326.     mov     [Image_Seg],ax
  327.  
  328.     mov     ax,0013h            ;change to 320x200x256 graph
  329.     int     10h
  330.  
  331.     call    Load_Tga
  332.     call    Setup_Step
  333.     call    Setup_Screen
  334.  
  335. @@MainLoop:
  336.     call    Scroll_Text
  337.     call    Display_Lines
  338.     mov     ah,1
  339.     int     16h
  340.     jz      @@MainLoop
  341.  
  342.     mov     ah,0                ;wait for a key press
  343.     int     16h
  344.     mov     ax,0003h            ;reset to 80x25x16 Char
  345.     int     10h
  346.  
  347.     mov     ax,4c00h            ;back to DOS
  348.     int     21h
  349. END START
  350.